import { reqDetail,reqAddCar} from "@/api"
import {getuuid} from "@/utils/getuuid"

const detail = {
    state: {
        detail:{},
        uuid:getuuid()
    },
    mutations: {
        GETDETAIL(state,data){
            state.detail=data
        }
    },
    actions: {
        async getDetail(context,skuId){
            let res=await reqDetail(skuId)
            if(res.code===200)context.commit('GETDETAIL',res.data)
        },
        async addCar(context,{skuId,skuNum}){
            let res=await reqAddCar(skuId,skuNum)
            if(res.code===200){
                return 'ok'
            }else{
                return Promise.reject(new Error('请求失败'))
            }
        },
    },
    getters: {
        categoryView(state){
            return state.detail.categoryView||''
        },
        skuInfo(state){
            return state.detail.skuInfo||{}
        },
        spuSaleAttrList(state){
            return state.detail.spuSaleAttrList||[]
        }
    }
}
export default detail